package edu.gdkm.dao;

import edu.gdkm.pojo.SubscriptionPlan;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface SubscriptionPlanDao {

    // 根据ID查询
    @Select("SELECT * FROM SubscriptionPlans WHERE plan_id = #{planId}")
    SubscriptionPlan selectById(Integer planId);

    // 查询所有
    @Select("SELECT * FROM SubscriptionPlans")
    List<SubscriptionPlan> selectAll();
    
    // 查询激活的订阅计划
    @Select("SELECT * FROM SubscriptionPlans WHERE is_active = #{isActive}")
    List<SubscriptionPlan> selectByIsActive(Boolean isActive);
    
    // 根据计费周期查询
    @Select("SELECT * FROM SubscriptionPlans WHERE billing_period = #{billingPeriod}")
    List<SubscriptionPlan> selectByBillingPeriod(String billingPeriod);

    // 新增
    @Insert("INSERT INTO SubscriptionPlans(name, description, price, billing_period, features, is_active) " +
            "VALUES(#{name}, #{description}, #{price}, #{billingPeriod}, #{features}, #{isActive})")
    @Options(useGeneratedKeys = true, keyProperty = "planId")
    int insert(SubscriptionPlan subscriptionPlan);

    // 更新
    @Update("UPDATE SubscriptionPlans SET name = #{name}, description = #{description}, price = #{price}, " +
            "billing_period = #{billingPeriod}, features = #{features}, is_active = #{isActive} " +
            "WHERE plan_id = #{planId}")
    int update(SubscriptionPlan subscriptionPlan);

    // 删除
    @Delete("DELETE FROM SubscriptionPlans WHERE plan_id = #{planId}")
    int delete(Integer planId);
}
    